package com.netafull.adapter;

import java.util.HashMap;
import java.util.List;

import com.netafull.R;
import com.netafull.analyze.Category;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryAdapter extends BaseAdapter {

	List<Category> items;
	Context context;
	public HashMap<Integer, Drawable> hm;

	public CategoryAdapter(List<Category> items, Context context) {
		super();
		this.items = items;
		this.context = context;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int arg0) {
		return items.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	
	public static class ViewHolder{
		TextView tv_public_date;
		TextView tv_title;
		TextView tv_description;
		ImageView iv_image;
	}

	@Override
	public View getView(final int position, View arg1, ViewGroup arg2) {
		Category temp = items.get(position);
		int image_flag = temp.getImg_flag();
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.category_list_item, null);
		
		ImageView img_category_item = (ImageView) view.findViewById(R.id.category_image);
		if(image_flag==0){
			img_category_item.setImageDrawable(null);
		}
		
		TextView tv_title = (TextView) view.findViewById(R.id.category_item);
		
		String s = temp.getCategory_name();
		String str = s+"("+String.valueOf(temp.getTitle_count())+")";
		
		
		if(str.length()<17){
			tv_title.getPaint().setFakeBoldText(true);
		} else {
			tv_title.setTextSize(16);
		}
		if(position<=1){
			//System.out.println(s);
			tv_title.setText(s);
		} else {
			//System.out.println("---->"+str);
			tv_title.setText(str);
		}
		return view;
	}

}
